<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <title>教师</title>
</head>

<jsp:include page="teacher_header.jsp"/>
<br>

<script>

    function insertWorks() {
        $.ajax({
            url: "${APP_PATH}" + "/insertWorks", //查看系统信息
            type: "POST",
            success: function (result) {
                console.log(result);
            }
        });
    }
</script>
<div class="container">
    <%--来自系统的消息：--%>
    <div class="row">
        <div class="col-md-12">
            <h4 class="text-danger">来自系统的消息：</h4>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover" id="sysMsg_table">
                <thead>
                <tr>
                    <th>发件人</th>
                    <th>有效期</th>
                    <th>收件人</th>
                    <th>消息</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>
    <br>
    <br>
    <%--最新审核消息--%>
    <div class="row">
        <div class="col-md-12">
            <h4 class="text-danger">管理员私信：</h4>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover" id="personalMsg_table">
                <thead>
                <tr>
                    <th>发件人</th>
                    <th>有效期</th>
                    <th>消息</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>

</div>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url: "${APP_PATH}" + "/sel_sys_msg", //查看系统信息
            type: "GET",
            success: function (result) {
                console.log(result);
                //1、解析并显示数据
                build_sys_msg(result);
            }
        });

        var teacherId = '<%=session.getAttribute("id_infor")%>';
        var id = teacherId;

        $.ajax({
            url: "${APP_PATH}" + "/sel_personal_msg",
            data: {"teacherId": id},
            type: "GET",
            success: function (result) {
                console.log(result);
                //1、解析并显示数据
                build_personal_msg(result);
            }
        });
    });

    function build_sys_msg(result) {
        //清空table表格
        $("#sysMsg_table tbody").empty();
        var emps = result.data;
        $.each(emps, function (index, item) {
            var fromUser = $("<td></td>").append(item.fromuser);
            var end = $("<td></td>").append(item.end);
            var toUser = $("<td></td>").append("所有教师");
            var message = $("<td></td>").append(item.message);

            $("<tr></tr>").append(fromUser).append(end)
                .append(toUser).append(message)
                .appendTo("#sysMsg_table tbody");
        });
    }

    function build_personal_msg(result) {
        //清空table表格
        $("#checkPaper_table tbody").empty();

        //重新渲染表格数据
        var emps = result.data;
        $.each(emps, function (index, item) {
            var resultUUIdTd = $("<td></td>").append(item.fromuser);
            var paperNameTd = $("<td></td>").append(item.end);
            var firstNameTd = $("<td></td>").append(item.message);
            $("<tr></tr>").append(resultUUIdTd).append(paperNameTd)
                .append(firstNameTd)
                .appendTo("#personalMsg_table tbody");

        });
    }

</script>
</body>
</html>
